using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ProtocToCSharp
{

    public static class FileHelper
    {
        public static List<FileInfo> GetAllFile(this DirectoryInfo directory)
        {
            List<FileInfo> children = new List<FileInfo>();

            children = children.Union(directory.GetFiles()).ToList();

            directory.GetDirectories().ToList().ForEach(c =>
            {
                children = children.Union(c.GetAllFile()).ToList();
            });

            return children;
        }
        public static List<FileInfo> GetAllFile(this DirectoryInfo directory, string searchPattern)
        {
            List<FileInfo> children = new List<FileInfo>();

            children = children.Union(directory.GetFiles(searchPattern)).ToList();

            directory.GetDirectories().ToList().ForEach(c =>
            {
                children = children.Union(c.GetAllFile(searchPattern)).ToList();
            });



            return children;
        }
    }
}
